package magicbattle.gui;


import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import javax.swing.JProgressBar;
import javax.swing.JLabel;

import magicbattle.game.Game;
import magicbattle.game.Player;

import java.awt.Color;
import java.awt.Font;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class GameGUI extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4859160162033973053L;
	private JPanel contentPane;
	
	/**
	 * Fields
	 * Player 1:
	 */
	private JProgressBar hpbar_p1;
	private JProgressBar mpbar_p1;
	private JLabel lbl_hp_p1;
	private JLabel lbl_mp_p1;

	/**
	 * Create the frame.
	 */
	public GameGUI(final Game game) {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 785, 542);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		JPanel panel = new JPanel();
		panel.setBounds(10, 11, 341, 282);
		contentPane.add(panel);
		panel.setLayout(null);

		// Health + Mana bar
		
		this.hpbar_p1 = new JProgressBar();
		this.hpbar_p1.setForeground(new Color(255, 51, 51));
		this.hpbar_p1.setBounds(73, 11, 125, 14);
		panel.add(this.hpbar_p1);

		this.mpbar_p1 = new JProgressBar();
		this.mpbar_p1.setForeground(new Color(0, 102, 255));
		this.mpbar_p1.setBounds(73, 36, 125, 14);
		panel.add(this.mpbar_p1);
		
		JLabel lbl_hp_txt_p1 = new JLabel("Health:");
		lbl_hp_txt_p1.setLabelFor(hpbar_p1);
		lbl_hp_txt_p1.setBounds(10, 11, 46, 14);
		panel.add(lbl_hp_txt_p1);
		
		JLabel lbl_mp_txt_p1 = new JLabel("Mana:");
		lbl_mp_txt_p1.setLabelFor(mpbar_p1);
		lbl_mp_txt_p1.setBounds(10, 36, 46, 14);
		panel.add(lbl_mp_txt_p1);
		
		this.lbl_hp_p1 = new JLabel("0/0");
		this.lbl_hp_p1.setBounds(208, 11, 89, 14);
		panel.add(this.lbl_hp_p1);
		
		this.lbl_mp_p1 = new JLabel("0/0");
		this.lbl_mp_p1.setBounds(208, 36, 89, 14);
		panel.add(this.lbl_mp_p1);
		
		JButton btnNewButton = new JButton("New button");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				for(int i = 0; i < 10000000;i++) {
					
				}
			}
		});
		btnNewButton.setBounds(99, 179, 89, 23);
		panel.add(btnNewButton);

		this.refreshData(game);
		
		this.setVisible(true);
	}
	
	public void refreshData(Game game) {
		Player players[] = game.getPlayer();
		Player player = players[0];
		
		// ---------------------------------------------------
		// Player 1
		// ---------------------------------------------------
		this.lbl_hp_p1.setText(Math.round(player.getHealth()) + "/" + Math.round(player.getCurrentAttribute().getHealth()));
		this.lbl_mp_p1.setText(Math.round(player.getMana()) + "/" + Math.round(player.getCurrentAttribute().getMana()));
		
		this.hpbar_p1.setValue(Math.round((100 * player.getHealth()) / player.getCurrentAttribute().getHealth()));
		this.mpbar_p1.setValue(Math.round((100 * player.getMana()) / player.getCurrentAttribute().getMana()));
	}
}
